﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace XmlDSigEx
{
    class CanonicalisationFactory
    {
        private static List<ICanonicalisationProvider> _Providers = new List<ICanonicalisationProvider>();

        static CanonicalisationFactory()
        {
            // Default configuration.
            AddProvider(new CanonicalisationProvider());
        }

        public static void AddProvider(ICanonicalisationProvider Provider)
        {
            _Providers.Insert(0, Provider);
        }

        public static ICanonicalisationAlgorithm GetCanonicalisation(string algorithm)
        {
            foreach (ICanonicalisationProvider Provider in _Providers)
            {
                if (Provider.CanHandle(algorithm))
                    return Provider.GetCanonicalisation(algorithm);
            }
            throw new UnknownAlgorithmException("No Provider was registered for the canonicalisation algorithm.");
        }
    }
}
